﻿using HCQ2_Common;
using HCQ2_Common.Constant;
using HCQ2_Model;
using HCQ2_Model.ViewModel.WebAPI;
using HCQ2_Model.VLine.InputDto._0410;
using HCQ2_Model.VLine.InputDto._0416;
using HCQ2_Model.VLine.OutputDto;
using HCQ2_Model.VLine.OutputDto._0416;
using HCQ2_Model.VLine.Params;
using HCQ2_Model.VRDD.InputDto;
using HCQ2_Model.VRDD.InputDto._0427;
using HCQ2_Model.VRDD.InputDto._0531;
using HCQ2_Model.VRDD.InputDto._0623;
using HCQ2_Model.VRDD.InputDto._0629;
using HCQ2_Model.VRDD.InputDto._0714;
using HCQ2_Model.VRDD.InputDto._0818;
using HCQ2_Model.VRDD.InputDto._20220620;
using HCQ2_Model.VRDD.InputDto._211026;
using HCQ2_Model.VRDD.OutputDto._0427;
using HCQ2_Model.VRDD.OutputDto._0525;
using HCQ2_Model.VRDD.OutputDto._0623;
using HCQ2_Model.VRDD.OutputDto._0629;
using HCQ2_Model.VRDD.OutputDto._0714;
using HCQ2_Model.VRDD.OutputDto._0818;
using HCQ2_Model.VRDD.OutputDto._20220620;
using HCQ2_Model.VRDD.OutputDto._211026;
using HCQ2UI_Helper.Session;
using HCQ2WebAPI_Logic.BaseAPIController;
using HCQ2WebAPI_Logic.Filters;
using HCQ2WebAPI_Logic.Model;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using System.Web.Http;

namespace HCQ2WebAPI_Logic.DocumentController
{
    /// <summary>
    ///  VR度度圈【2021-06-23】【2021-06-29】【2021-07-14】需求
    /// </summary>
    public class VRDDStoreController : BaseWeiXinApiLogic
    {
        //****************************************************2021-06-23需求*******************************************************
        #region 2.1 ✔更新店铺简介 + WebApiResultJsonModel ModifyStoreInfo(InputStoreInfo param)
        /// <summary>
        ///  2.1 ✔更新店铺简介
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel ModifyStoreInfo(InputStoreInfo param)
        {
            //1.0 验证数据有效性
            if (!ModelState.IsValid)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            if (param.fileSortType <= 0 || param.fileSortType > 6)
                param.fileSortType = 3;
            var mark = operateContext.bllSession.T_DocumentFolder.FindSingle(s => s.folder_id == param.folder_id);
            if (mark == null)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "店铺信息不存在！", "");
            //判断是否需要处理服务类别
            if (string.IsNullOrEmpty(mark.bs_type) || !mark.bs_type.Equals(param.bs_type))
            {
                //需要处理基础服务类别
                //查询原始服务类别
                var ob = operateContext.bllSession.T_VRDDCircleBaseService.FindSingle(s => s.s_type.Equals(mark.bs_type));
                if (ob != null && ob.s_num <= 1)
                    //清理原始服务类别
                    operateContext.bllSession.T_VRDDCircleBaseService.Delete(s => s.id == ob.id);
                //查询新的服务类别是否存在
                var bs = operateContext.bllSession.T_VRDDCircleBaseService.FindSingle(s => s.s_type.Equals(param.bs_type));
                if (bs == null)
                    //添加服务基础数据
                    operateContext.bllSession.T_VRDDCircleBaseService.Add(new T_VRDDCircleBaseService { s_type = param.bs_type, s_num = 1, create_date = DateTime.Now, update_date = DateTime.Now });
                else
                    operateContext.bllSession.T_VRDDCircleBaseService.Modify(new T_VRDDCircleBaseService { s_num = bs.s_num + 1 }, s => s.id == bs.id, "s_num");
            }
            //2、更新目录树
            operateContext.bllSession.T_DocumentFolder.Modify(new T_DocumentFolder { sortType = param.fileSortType, statr_partner = param.statr_partner, bs_type = param.bs_type, bs_note = param.bs_note, folder_note = param.bs_note }, s => s.folder_id == param.folder_id, "sortType", "statr_partner", "bs_type", "bs_note", "folder_note");
            return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "店铺简介更新成功！", "");
        }
        #endregion

        #region 2.2 ✔更新店铺位置信息 + WebApiResultJsonModel ModifyFolderGPS(InputFolderGPS param)
        /// <summary>
        ///  2.2 ✔更新店铺位置信息
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        /// <remarks>
        /// 1、需求变更： 禅道id：228 日期：【2021-11-12】<br/>
        /// </remarks>
        [HttpPost]
        public WebApiResultJsonModel ModifyFolderGPS(InputFolderGPS param)
        {
            //1.0 验证数据有效性
            if (!ModelState.IsValid)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            if (!string.IsNullOrEmpty(param.floor_list))
                param.floor_list = param.floor_list.Replace("，", ",").Trim(',');
            operateContext.bllSession.T_DocumentFolder.Modify(new T_DocumentFolder { floor_level = param.floor_list, gps_x = param.gps_x, gps_y = param.gps_y, addr = param.addr, city = param.city, deliveryDistance = param.deliveryDistance }, s => s.folder_id == param.folder_id, "gps_x", "gps_y", "addr", "floor_level", "city", "deliveryDistance");
            return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "店铺位置信息更新成功！", "");
        }
        #endregion

        #region 2.3 ✔更新商品位置信息 + WebApiResultJsonModel ModifyProductGPS(InputProductGPS param)
        /// <summary>
        ///  2.3 ✔更新商品位置信息
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel ModifyProductGPS(InputProductGPS param)
        {
            //1.0 验证数据有效性
            if (!ModelState.IsValid)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            int mark = operateContext.bllSession.T_DocumentInfo.Modify(new T_DocumentInfo { doc_number = param.doc_number, gps_x = param.gps_x, gps_y = param.gps_y }, s => s.file_id == param.file_id, "gps_x", "gps_y", "doc_number");
            if (mark > 0)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "商品位置信息更新成功！", "");
            return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "商品位置信息更新失败！", "");
        }
        #endregion

        #region 2.4 ✔按商品或店铺获取服务信息 + WebApiResultJsonModel GetServiceByProduct(InputServiceByProduct param)
        /// <summary>
        ///  2.4 ✔按商品或店铺获取服务信息
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel<List<ServiceByProduct>> GetServiceByProduct(InputServiceByProduct param)
        {
            if (param.file_id <= 0 && param.dd_id <= 0 && string.IsNullOrEmpty(param.folder_path))
                return ApiResultJsonModel<List<ServiceByProduct>>.RedirectWebApi(WebResultCode.Exception, "file_id、dd_id、folder_path不能同时为空！", null);
            var list = operateContext.bllSession.T_VRDDCircleBaseService.GetServiceByProduct(param);
            return ApiResultJsonModel<List<ServiceByProduct>>.RedirectWebApi(WebResultCode.Ok, "成功获取服务信息~", list);
        }
        #endregion

        #region 2.5 ✔按位置获取服务信息 + WebApiResultJsonModel GetServiceByGPS(InputServiceByGPS param)
        /// <summary>
        ///  2.5 ✔按位置获取服务信息
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel<List<ServiceByProduct>> GetServiceByGPS(InputServiceByGPS param)
        {
            //1.0 验证数据有效性
            if (!ModelState.IsValid)
                return ApiResultJsonModel<List<ServiceByProduct>>.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            if (param.folder_id <= 0 && string.IsNullOrEmpty(param.folder_path))
                return ApiResultJsonModel<List<ServiceByProduct>>.RedirectWebApi(WebResultCode.Exception, "店铺folder_id和folder_path不能同时为空！", null);
            var list = operateContext.bllSession.T_VRDDCircleBaseService.GetServiceByGPS(param);
            return ApiResultJsonModel<List<ServiceByProduct>>.RedirectWebApi(WebResultCode.Ok, "成功获取服务信息~", list);
        }
        #endregion

        #region 2.6 ✔删除服务信息 + WebApiResultJsonModel DeleteService(InputService param)
        /// <summary>
        ///  2.6 ✔删除服务信息
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel DeleteService(InputServiceDel param)
        {
            //1.0 验证数据有效性
            if (param.id <= 0)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "服务id异常！", null);
            int mark = operateContext.bllSession.T_VRDDCircleBaseService.SelectCount(s => s.id == param.id);
            if (mark <= 0)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "服务不存在！", "");
            mark = operateContext.bllSession.T_VRDDCircleBaseService.Delete(s => s.id == param.id);
            if (mark > 0)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "服务删除成功！", "");
            return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "服务删除失败！", "");
        }
        #endregion

        #region 2.7 ✔设置商品是否主商品 + WebApiResultJsonModel SetProductIsMain(InputProductIsMain param)
        /// <summary>
        ///  2.7 ✔设置商品是否主商品
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel SetProductIsMain(InputProductIsMain param)
        {
            //1.0 验证数据有效性
            if (!ModelState.IsValid)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            var file = operateContext.bllSession.T_DocumentInfo.FindSingle(s => s.file_id == param.file_id);
            if (file == null)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "当前商品已删除或下架！", "");
            //2 修改相同店铺其他商品为非主商品
            if (file.store_id > 0)
                operateContext.bllSession.T_DocumentInfo.Modify(new T_DocumentInfo { is_mian = false }, s => s.store_id == file.store_id, "is_mian");
            //3 设置当前商品为主商品
            int mark = operateContext.bllSession.T_DocumentInfo.Modify(new T_DocumentInfo { is_mian = true }, s => s.file_id == param.file_id, "is_mian");
            if (mark > 0)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "商品属性设置成功！", "");
            return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "商品属性设置失败！", "");
        }
        #endregion

        //****************************************************2021-06-29需求*******************************************************
        #region 1.3 ✔获取用户的最新商品 + WebApiResultJsonModel GetUserArticle(InputUserArticle param)
        /// <summary>
        ///  1.3 ✔获取用户的最新商品
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel<OutputUserArticle> GetUserArticle(InputUserArticle param)
        {
            //1.0 验证数据有效性
            if (!ModelState.IsValid)
                return ApiResultJsonModel<OutputUserArticle>.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            if (param.size <= 0)
                param.size = 10;
            var result = operateContext.bllSession.DD_User.GetArticleParamList(param);
            return ApiResultJsonModel<OutputUserArticle>.RedirectWebApi(WebResultCode.Ok, "获取用户的最新商品！", result);
        }
        #endregion

        #region 1.4 ✔获取用户的最新动态 + WebApiResultJsonModel GetUserDynamic(InputUserArticle param)
        /// <summary>
        ///  1.4 ✔获取用户的最新动态
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel<OutputUserDynamic> GetUserDynamic(InputUserArticle param)
        {
            //1.0 验证数据有效性
            if (!ModelState.IsValid)
                return ApiResultJsonModel<OutputUserDynamic>.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            if (param.size <= 0)
                param.size = 10;
            var result = operateContext.bllSession.DD_User.GetUserDynamic(param);
            return ApiResultJsonModel<OutputUserDynamic>.RedirectWebApi(WebResultCode.Ok, "获取用户的最新动态！", result);
        }
        #endregion

        #region 1.5 ✔提交对服务的已读状态 + WebApiResultJsonModel ModifyServiceStatus(InputServiceStatus param)
        /// <summary>
        ///  1.5 ✔提交对服务的已读状态
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel ModifyServiceStatus(InputServiceStatus param)
        {
            //1.0 验证数据有效性
            if (!ModelState.IsValid)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            var obj = operateContext.bllSession.T_VRDDCircleReadService.FindSingle(s => s.du_id == param.user_id && s.s_id == param.id);
            if (obj != null)
                operateContext.bllSession.T_VRDDCircleReadService.Modify(new T_VRDDCircleReadService { read_date = DateTime.Now }, s => s.id == obj.id, "read_date");
            else
                operateContext.bllSession.T_VRDDCircleReadService.Add(new T_VRDDCircleReadService { du_id = param.user_id, s_id = param.id, read_date = DateTime.Now });
            return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "成功提交服务的已读状态！", "");
        }
        #endregion

        #region 1.6 ✔获取服务信息 + WebApiResultJsonModel GetUserServiceList(InputUserArticle param)
        /// <summary>
        ///  1.6 ✔获取服务信息
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        /// <remarks>
        ///  1、只返回在有效期内的服务<br/>
        ///  2、综合排序为按以下优先级对结果进行排序：<br/>
        ///      1)是否VIP（是VIP的在前）
        ///      2)是否关注（我关注的用户在前）
        ///      3)距离（距离小的在前）
        ///      4)时间（新发布的在前)
        /// </remarks>
        [HttpPost]
        public WebApiResultJsonModel<OutputUserDynamic> GetUserServiceList(InputUserArticle param)
        {
            //1.0 验证数据有效性
            if (!ModelState.IsValid)
                return ApiResultJsonModel<OutputUserDynamic>.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            if (param.size <= 0)
                param.size = 10;
            var result = operateContext.bllSession.DD_User.GetUserDynamic(param);
            return ApiResultJsonModel<OutputUserDynamic>.RedirectWebApi(WebResultCode.Ok, "成功获取服务信息！", result);
        }
        #endregion

        #region 1.7 ✔获取共同好友列表 + WebApiResultJsonModel GetMutualFriend(InputMutualFriend param)
        /// <summary>
        ///  1.7 ✔获取共同好友列表
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel<List<OutputMutualFriend>> GetMutualFriend(InputMutualFriend param)
        {
            //1.0 验证数据有效性
            if (!ModelState.IsValid)
                return ApiResultJsonModel<List<OutputMutualFriend>>.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            if (string.IsNullOrEmpty(param.userid) && param.user_id <= 0)
                return ApiResultJsonModel<List<OutputMutualFriend>>.RedirectWebApi(WebResultCode.Exception, "登录用户信息，userid、user_id不可同时为空！", null);
            if (string.IsNullOrEmpty(param.duid) && param.du_id <= 0)
                return ApiResultJsonModel<List<OutputMutualFriend>>.RedirectWebApi(WebResultCode.Exception, "登录用户信息，duid、du_id不可同时为空！", null);
            if (param.user_id <= 0 && !string.IsNullOrEmpty(param.userid))
                param.user_id = SysPermissSession.ChangeIdByGuid(param.userid);
            if (param.du_id <= 0 && !string.IsNullOrEmpty(param.duid))
                param.du_id = SysPermissSession.ChangeIdByGuid(param.duid);
            var list = operateContext.bllSession.DD_User.GetMutualFriend(param);
            return ApiResultJsonModel<List<OutputMutualFriend>>.RedirectWebApi(WebResultCode.Ok, "成功获取共同好友列表！", list);
        }
        #endregion

        //****************************************************2021-07-14需求*******************************************************
        #region 3.14 ✔获取店铺商品折扣信息 + WebApiResultJsonModel GetUserArticle(InputUserArticle param)
        /// <summary>
        ///  3.14 ✔获取店铺商品折扣信息
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        /// <remarks>
        /// 1、需求变更： 禅道id：220 日期：2021-11-12<br/>
        /// </remarks>
        [HttpPost]
        public WebApiResultJsonModel<List<OutputGoodRate>> GetGoodsRateByStore(InputGoodRate param)
        {
            //1.0 验证数据有效性
            if (!ModelState.IsValid)
                return ApiResultJsonModel<List<OutputGoodRate>>.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            if (param.store_id <= 0 && string.IsNullOrEmpty(param.folderPath))
                return ApiResultJsonModel<List<OutputGoodRate>>.RedirectWebApi(WebResultCode.Exception, "店铺id、folderPath不能同时为空！", null);
            int user_id = 0;
            if (!string.IsNullOrEmpty(param.userid))
                user_id = SysPermissSession.ChangeIdByGuid(param.userid);
            var result = operateContext.bllSession.T_VRGoodDiscount.GetGoodsRateByStore(param, user_id);
            return ApiResultJsonModel<List<OutputGoodRate>>.RedirectWebApi(WebResultCode.Ok, "成功获取店铺所有商品折扣信息！", result);
        }
        #endregion

        #region 3.15 ✔保存店铺的用户等级配置 + WebApiResultJsonModel SaveUserLevelByStore(InputUserLevelStore param)
        /// <summary>
        ///  3.15 ✔保存店铺的用户等级配置 
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        /// <remarks>
        ///  1、同一个店铺、同一个用户等级只能存在一条记录；如果提交的数据已存在，则返回提示：该等级配置数据已存在；<br/>
        /// </remarks>
        [HttpPost]
        public WebApiResultJsonModel SaveUserLevelByStore(InputUserLevelStore param)
        {
            //1.0 验证数据有效性
            if (!ModelState.IsValid)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            string user_name = operateContext.bllSession.T_User.FindSingle(s => s.user_id == param.user_id)?.user_name;
            if (string.IsNullOrEmpty(user_name))
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "传递的用户id信息异常！", null);
            var folder = operateContext.bllSession.T_DocumentFolder.SelectCount(s => s.folder_id == param.store_id && !s.if_remove);
            if (folder <= 0)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "后台查无此店铺！", null);
            var level = operateContext.bllSession.T_VRUserLevel.FindSingle(s => s.store_id == param.store_id && s.user_level == param.user_level);
            int levelCount = 1;
            if (level != null)
            {
                //编辑
                operateContext.bllSession.T_VRUserLevel.Modify(new T_VRUserLevel
                {
                    min_sale = param.min_sale,
                    max_sale = param.max_sale,
                    min_line = param.min_line,
                    max_line = param.max_line,
                    price_rate = param.rate,
                    level_note = param.note
                }, s => s.id == level.id, "min_sale", "max_sale", "min_line", "max_line", "price_rate", "level_note");
            }
            else
            {
                //新增
                levelCount = operateContext.bllSession.T_VRUserLevel.Add(new T_VRUserLevel
                {
                    store_id = param.store_id,
                    user_level = param.user_level,
                    min_sale = param.min_sale,
                    max_sale = param.max_sale,
                    min_line = param.min_line,
                    max_line = param.max_line,
                    price_rate = param.rate,
                    level_note = param.note,
                    create_id = param.user_id,
                    create_name = user_name,
                    create_date = DateTime.Now,
                    update_id = param.user_id,
                    update_name = user_name,
                    update_date = DateTime.Now
                });
            }
            if (levelCount > 0)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "店铺用户等级配置成功！", "");
            return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "店铺用户等级配置失败！", "");
        }
        #endregion

        #region 3.16 ✔更新店铺的用户等级配置 + WebApiResultJsonModel ModifyUserLevelByStore(InputModifyUserLevelStore param)
        /// <summary>
        ///  3.16 ✔ 更新店铺的用户等级配置 
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        /// <remarks>
        ///  1、同一个店铺、同一个用户等级只能存在一条记录；如果提交的数据已存在（当前修改的ID除外），则返回提示：该等级配置数据已存在；<br/>
        /// </remarks>
        [HttpPost]
        public WebApiResultJsonModel ModifyUserLevelByStore(InputModifyUserLevelStore param)
        {
            //1.0 验证数据有效性
            if (!ModelState.IsValid)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            string user_name = operateContext.bllSession.T_User.FindSingle(s => s.user_id == param.user_id)?.user_name;
            if (string.IsNullOrEmpty(user_name))
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "传递的用户id信息异常！", null);
            var level = operateContext.bllSession.T_VRUserLevel.FindSingle(s => s.id == param.id);
            if (level == null)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "配置id信息异常！", null);
            var levelCount = operateContext.bllSession.T_VRUserLevel.SelectCount(s => s.store_id == level.store_id && s.user_level == param.user_level && s.id != param.id);
            if (levelCount > 0)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "该等级配置数据已存在！", null);
            T_VRUserLevel userLevel = new T_VRUserLevel
            {
                user_level = param.user_level,
                min_sale = param.min_sale,
                max_sale = param.max_sale,
                min_line = param.min_line,
                max_line = param.max_line,
                price_rate = param.rate,
                level_note = param.note,
                update_id = param.user_id,
                update_name = user_name,
                update_date = DateTime.Now
            };
            operateContext.bllSession.T_VRUserLevel.Modify(userLevel, s => s.id == param.id, "user_level", "min_sale", "max_sale", "min_line", "max_line", "price_rate", "level_note", "update_id", "update_date");
            return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "店铺用户等级更新成功！", "");
        }
        #endregion

        #region 3.17 ✔获取店铺用户等级配置 + WebApiResultJsonModel GetUserLevelByStore(InputGoodRate param)
        /// <summary>
        ///  3.17 ✔获取店铺用户等级配置
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel<List<OutputUserLevelByStore>> GetUserLevelByStore(InputGoodRate param)
        {
            //1.0 验证数据有效性
            if (!ModelState.IsValid)
                return ApiResultJsonModel<List<OutputUserLevelByStore>>.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            List<OutputUserLevelByStore> list = new List<OutputUserLevelByStore>();
            var result = operateContext.bllSession.T_VRUserLevel.Select(s => s.store_id == param.store_id).OrderBy(s => s.user_level)?.ToList();
            result?.ForEach(s => list.Add(new OutputUserLevelByStore
            {
                id = s.id,
                store_id = s.store_id,
                user_level = s.user_level,
                min_sale = s.min_sale,
                max_sale = s.max_sale,
                min_line = s.min_line,
                max_line = s.max_line,
                rate = s.price_rate,
                note = s.level_note
            }));
            return ApiResultJsonModel<List<OutputUserLevelByStore>>.RedirectWebApi(WebResultCode.Ok, "成功获取店铺用户等级配置！", list);
        }
        #endregion

        #region 3.18 ✔获取用户店铺等级成长值 + WebApiResultJsonModel GetUserGrowUpByStore(InputUserLevelGrowUp param)
        /// <summary>
        ///  3.18 ✔ 获取用户店铺等级成长值
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        /// <remarks>
        ///  1、销售额差值=下一等级销售额最小值-年销售额；<br/>
        ///  2、下线人数差值=下一等级下线人数最小值-下线人数；<br/>
        /// </remarks>
        [HttpPost]
        public WebApiResultJsonModel<OutputUserGrow> GetUserGrowUpByStore(InputUserLevelGrowUp param)
        {
            //1.0 验证数据有效性
            if (!ModelState.IsValid)
                return ApiResultJsonModel<OutputUserGrow>.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            //判断用户是否存在
            int mark = operateContext.bllSession.T_User.SelectCount(s => s.user_id == param.user_id);
            if (mark <= 0)
                return ApiResultJsonModel<OutputUserGrow>.RedirectWebApi(WebResultCode.Exception, "用户id信息异常！", null);
            //判断店铺是否存在
            mark = operateContext.bllSession.T_DocumentFolder.SelectCount(s => s.folder_id == param.store_id);
            if (mark <= 0)
                return ApiResultJsonModel<OutputUserGrow>.RedirectWebApi(WebResultCode.Exception, "店铺id信息异常！", null);
            var result = operateContext.bllSession.T_VRUserLevel.GetUserGrowUpByStore(param);
            return ApiResultJsonModel<OutputUserGrow>.RedirectWebApi(WebResultCode.Ok, "成功获取用户店铺等级成长值！", result);
        }
        #endregion

        #region 3.19 ✔设置是否启用合伙人 + WebApiResultJsonModel SetStartPartner(InputStartParner param)
        /// <summary>
        ///  3.19 ✔ 设置是否启用合伙人 
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel SetStartPartner(InputStartParner param)
        {
            //1.0 验证数据有效性
            if (!ModelState.IsValid)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            //判断店铺是否存在
            int mark = operateContext.bllSession.T_DocumentFolder.SelectCount(s => s.folder_id == param.store_id);
            if (mark <= 0)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "店铺id信息异常！", null);
            operateContext.bllSession.T_DocumentFolder.Modify(new T_DocumentFolder { statr_partner = param.statr_partner }, s => s.folder_id == param.store_id, "statr_partner");
            return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "成功设置是否启用合伙人！", "");
        }
        #endregion

        #region 3.20 ✔获取合伙人协议内容 + WebApiResultJsonModel GetParnerDealByStore(InputParnerDeal param)
        /// <summary>
        ///  3.20 ✔ 获取合伙人协议内容
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        /// <remarks>
        ///  获取店铺的合伙人协议<br/>
        /// </remarks>
        [HttpPost]
        public WebApiResultJsonModel<string> GetParnerDealByStore(InputParnerDeal param)
        {
            //1.0 验证数据有效性
            if (!ModelState.IsValid)
                return ApiResultJsonModel<string>.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            var folder = operateContext.bllSession.T_DocumentFolder.SelectCount(s => s.folder_id == param.store_id && !s.if_remove);
            if (folder <= 0)
                return ApiResultJsonModel<string>.RedirectWebApi(WebResultCode.Exception, "后台查无此店铺！", null);
            string deal_note = operateContext.bllSession.T_VRFounderDeal.FindSingle(s => s.folder_id == param.store_id)?.deal_note;
            if (param.deal_type == 1 || !string.IsNullOrEmpty(deal_note))
                return ApiResultJsonModel<string>.RedirectWebApi(WebResultCode.Ok, "成功获取合伙人协议！", deal_note);
            //本店铺协议为空，向上获取根协议
            int rootId = operateContext.bllSession.T_VRUserLevel.GetRootIdByStore(param.store_id);
            deal_note = operateContext.bllSession.T_VRFounderDeal.FindSingle(s => s.folder_id == rootId)?.deal_note;
            return ApiResultJsonModel<string>.RedirectWebApi(WebResultCode.Ok, "成功获取合伙人协议！", deal_note);
        }
        #endregion

        #region 3.22 ✔获取合伙人协议页面地址 + WebApiResultJsonModel GetParnerDealUrlByStore(InputParnerDeal param)
        /// <summary>
        ///  3.22 ✔ 获取合伙人协议页面地址
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        /// <remarks>
        ///  获取店铺的合伙人协议<br/>
        /// </remarks>
        [HttpPost]
        public WebApiResultJsonModel<string> GetParnerDealUrlByStore(InputParnerDeal param)
        {
            //1.0 验证数据有效性
            if (!ModelState.IsValid)
                return ApiResultJsonModel<string>.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            var folder = operateContext.bllSession.T_DocumentFolder.SelectCount(s => s.folder_id == param.store_id && !s.if_remove);
            if (folder <= 0)
                return ApiResultJsonModel<string>.RedirectWebApi(WebResultCode.Exception, "后台查无此店铺！", null);
            var deal = operateContext.bllSession.T_VRFounderDeal.FindSingle(s => s.folder_id == param.store_id);
            string dealUrl = string.Empty;
            //获取店铺协议
            if (!string.IsNullOrEmpty(deal.deal_note))
                dealUrl = HttpContext.Current.Request.Url.AbsoluteUri.Substring(0, HttpContext.Current.Request.Url.AbsoluteUri.IndexOf("/api/")) + $"/uploadFile/FouderPact/FouderPact.html?id={deal.id}";
            if (param.deal_type == 1)
                return ApiResultJsonModel<string>.RedirectWebApi(WebResultCode.Ok, "成功获取合伙人协议页面地址！", dealUrl);
            else
            {
                //当前店铺协议为空时，向上获取根协议
                if (string.IsNullOrEmpty(deal.deal_note))
                {
                    //本店铺协议为空，向上获取根协议
                    int rootId = operateContext.bllSession.T_VRUserLevel.GetRootIdByStore(param.store_id);
                    deal = operateContext.bllSession.T_VRFounderDeal.FindSingle(s => s.folder_id == rootId);
                    dealUrl = HttpContext.Current.Request.Url.AbsoluteUri.Substring(0, HttpContext.Current.Request.Url.AbsoluteUri.IndexOf("/api/")) + $"/uploadFile/FouderPact/FouderPact.html?id={deal.id}";
                }
            }
            return ApiResultJsonModel<string>.RedirectWebApi(WebResultCode.Ok, "成功获取合伙人协议页面地址！", dealUrl);
        }
        #endregion

        #region 3.21 ✔删除店铺用户等级配置 + WebApiResultJsonModel DeleteUserLevelByStore(InputUserLevelDel param)
        /// <summary>
        ///  3.21 ✔删除店铺用户等级配置 
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel DeleteUserLevelByStore(InputUserLevelDel param)
        {
            //1.0 验证数据有效性
            if (!ModelState.IsValid)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            int mark = operateContext.bllSession.T_VRUserLevel.SelectCount(s => s.id == param.id);
            if (mark <= 0)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "待删除的用户等级配置不存在！", null);
            mark = operateContext.bllSession.T_VRUserLevel.Delete(s => s.id == param.id);
            if (mark > 0)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "店铺用户等级配置删除成功！", "");
            return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "店铺用户等级配置删除失败！", "");
        }
        #endregion

        //****************************************************2021-10-26需求【点播】*******************************************************
        #region 4.0 ✔保存点播列表 + WebApiResultJsonModel SavePlayTable(InputPlayTable param)
        /// <summary>
        ///  4.0 ✔ 保存点播列表 
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel SavePlayTable(InputPlayTable param)
        {
            //1.0 验证数据有效性
            if (!ModelState.IsValid)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            var u = operateContext.bllSession.T_User.FindSingle(s => s.user_guid.Equals(param.userid));
            if (u == null)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "传递的用户编码userid有误，请核实！", null);
            //判断商品id是否存在
            int mark = operateContext.bllSession.T_DocumentInfo.SelectCount(s => s.file_id == param.CommodityID && s.file_status == 5 && !s.if_remove);
            if (mark <= 0)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "传递的商品id后台不存在、已删除或未上架，请核实！", null);
            T_VRPlayList play = new T_VRPlayList
            {
                OrderCode = param.OrderCode,
                userid = param.userid,
                user_name = u.user_name,
                CommodityID = param.CommodityID,
                DeviceCode = param.DeviceCode,
                Content = param.Content,
                PlayStatus = 0,
                CreateId = u.user_id,
                CreateDate = DateTime.Now,
                UpdateDate = DateTime.Now
            };
            mark = operateContext.bllSession.T_VRPlayList.Add(play);
            if (mark <= 0)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "点播列表保存失败！", null);
            //文件上传路径
            string pathServer = "/uploadFile/VRPlayFile/" + u.user_guid + "/" + DateTime.Now.ToString("yyyyMMdd") + "/";
            string uploadPath = request.MapPath(request.ApplicationPath + pathServer);
            if (!Directory.Exists(uploadPath))
                Directory.CreateDirectory(uploadPath);
            //添加成功保存图片列表
            param.picture.ForEach(o =>
            {
                string picName = Guid.NewGuid().ToString().Replace("-", ""), prefixStr = o.Picture.Split(';')[0].ToString().Split('/')[1];
                byte[] picByte = Convert.FromBase64String(o.Picture.Split(',')[1]);
                string tempName = ImageHelper.CreateImageFromBytes(uploadPath, picName, picByte, prefixStr);
                if (!string.IsNullOrEmpty(tempName))
                    operateContext.bllSession.T_VRPlayPictureList.Add(new T_VRPlayPictureList
                    {
                        playId = play.id,
                        pictureUrl = "~" + pathServer + picName + "." + prefixStr //文件存放路径
                    });
            });
            return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "点播列表保存成功！", "");
        }
        #endregion

        #region 4.1 ✔更新点播状态 + WebApiResultJsonModel UpdatePlayStatus(InputPlayStatus param)
        /// <summary>
        ///  4.1 ✔ 更新点播状态 
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel UpdatePlayStatus(InputPlayStatus param)
        {
            //1.0 验证数据有效性
            if (!ModelState.IsValid)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            int mark = operateContext.bllSession.T_VRPlayList.SelectCount(s => s.id == param.id);
            if (mark <= 0)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "传递的点播ID有误，请核实！", null);
            mark = operateContext.bllSession.T_VRPlayList.Modify(new T_VRPlayList { PlayStatus = param.PlayStatus, UpdateDate = DateTime.Now }, s => s.id == param.id, "PlayStatus", "UpdateDate");
            if (mark > 0)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "点播状态更新成功！", "");
            return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "点播状态更新失败！", null);
        }
        #endregion

        #region 4.2 ✔获取点播列表 + WebApiResultJsonModel GetPlayTable(QueryPlayTable param)
        /// <summary>
        ///  4.2 ✔ 获取点播列表
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel<List<OutputPlayTable>> GetPlayTable(QueryPlayTable param)
        {
            //1.0 验证数据有效性
            if (!ModelState.IsValid)
                return ApiResultJsonModel<List<OutputPlayTable>>.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            if (string.IsNullOrEmpty(param.DeviceCode) && string.IsNullOrEmpty(param.userid))
                return ApiResultJsonModel<List<OutputPlayTable>>.RedirectWebApi(WebResultCode.Exception, "设备代码和用户编码不能同时为空！", null);
            var list = operateContext.bllSession.T_VRPlayList.GetPlayTable(param);
            return ApiResultJsonModel<List<OutputPlayTable>>.RedirectWebApi(WebResultCode.Ok, "成功获取点播列表！", list);
        }
        #endregion

        #region 4.3 ✔获取商品视频地址 + WebApiResultJsonModel GetGoodVideoUrl(QueryVideoUrl param)
        /// <summary>
        ///  4.3 ✔ 获取商品视频地址
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel<string> GetGoodVideoUrl(QueryVideoUrl param)
        {
            //1.0 验证数据有效性
            if (!ModelState.IsValid)
                return ApiResultJsonModel<string>.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            var file = operateContext.bllSession.T_DocumentInfo.FindSingle(s => s.file_id == param.CommodityID);
            if (file == null)
                return ApiResultJsonModel<string>.RedirectWebApi(WebResultCode.Exception, "传递的商品id后台不存在或已删除！", null);
            return ApiResultJsonModel<string>.RedirectWebApi(WebResultCode.Ok, "成功获取商品视频地址！", file.vUrl);
        }
        #endregion

        #region 4.4 ✔保存店铺关注 + WebApiResultJsonModel SaveStoreHold(InputSaveStoreHold param)
        /// <summary>
        /// 4.4 ✔保存店铺关注
        /// </summary>
        /// <param name="param">请求参数</param>
        /// <returns></returns>
        /// <remarks>
        /// 20220616需求
        /// </remarks>
        [HttpPost]
        [ModelValid]
        public WebApiResultJsonModel SaveStoreHold(InputSaveStoreHold param)
        {
            //1.0、用户编码
            var user_id = SysPermissSession.ChangeIdByGuid(param.userid);
            if(user_id<=0)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "登录用户编码信息异常！", null);
            var owner_id= SysPermissSession.ChangeIdByGuid(param.ownserID);
            if (owner_id <= 0)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "合伙人或创始人用户编码信息异常 ！", null);
            //1.1、店铺
            var folder = operateContext.bllSession.T_DocumentFolder.FindSingle(s => s.folder_id == param.folderID);
            if(null==folder)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "店铺id异常！", null);
            //2.0、关注店铺
            if (folder.founder_id == owner_id)
            {
                var star = operateContext.bllSession.T_VRUserFolder.SelectCount(s => s.user_guid.Equals(param.userid) && s.folder_id == param.folderID && s.folder_type == 0);
                int focus_num = folder.focus_num;
                //加关注
                if (param.status == 1)
                {
                    if(star>0)
                        return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "已添加过关注！", folder.focus_num);
                    var folderStar = operateContext.bllSession.T_VRUserFolder.Add(new T_VRUserFolder
                    {
                        user_guid = param.userid,
                        folder_id = folder.folder_id,
                        folder_pid = folder.folder_pid,
                        folder_path = folder.folder_path,
                        folder_type = 0,
                        partner_id = 0,
                        folder_date = DateTime.Now
                    });
                    if (folderStar > 0)
                    {
                        focus_num = focus_num + 1;
                        operateContext.bllSession.T_DocumentFolder.Modify(new T_DocumentFolder { focus_num = focus_num }, s => s.folder_id == folder.folder_id, "focus_num");
                    }
                    return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "添加店铺关注成功！", focus_num);
                }
                //取消关注
                else
                {
                    if(star<=0)
                        return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "当前用户并未关注过该店铺无需取消！", folder.focus_num);
                    var folderStar = operateContext.bllSession.T_VRUserFolder.Delete(s => s.user_guid.Equals(param.userid) && s.folder_id == param.folderID && s.folder_type == 0);
                    if (folderStar > 0)
                    {
                        focus_num = focus_num - 1;
                        operateContext.bllSession.T_DocumentFolder.Modify(new T_DocumentFolder { focus_num = focus_num }, s => s.folder_id == folder.folder_id, "focus_num");
                    }
                    return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "取消店铺关注成功！", focus_num);
                }
            }
            //2.1、关注合伙店铺
            var apply = operateContext.bllSession.T_VRFounderApply.FindSingle(s => s.user_id == owner_id && s.folder_id == param.folderID && s.apply_status == 1);
            //店铺合伙人
            if(null!= apply)
            {
                //合伙人店铺
                var star = operateContext.bllSession.T_VRUserFolder.SelectCount(s => s.user_guid.Equals(param.userid) && s.folder_id == param.folderID && s.ownerID.Equals(param.ownserID) && s.folder_type == 1);
                int focus_num = apply.focus_num;
                //加关注
                if (param.status == 1)
                {
                    if(star>0)
                        return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "已添加过关注！", focus_num);
                    var folderStar = operateContext.bllSession.T_VRUserFolder.Add(new T_VRUserFolder
                    {
                        user_guid = param.userid,
                        folder_id = folder.folder_id,
                        folder_pid = folder.folder_pid,
                        folder_path = folder.folder_path,
                        folder_type = 1,
                        ownerID = param.ownserID,
                        partner_id = apply.id,
                        folder_date = DateTime.Now
                    });
                    if (folderStar > 0)
                    {
                        focus_num += 1;
                        operateContext.bllSession.T_VRFounderApply.Modify(new T_VRFounderApply { focus_num = focus_num }, s => s.id == apply.id, "focus_num");
                    }
                    return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "添加店铺关注成功！", focus_num);
                }
                //取消关注
                else
                {
                    if (star <= 0)
                        return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "当前用户并未关注过该合伙店铺无需取消！", focus_num);
                    var folderStar = operateContext.bllSession.T_VRUserFolder.Delete(s => s.user_guid.Equals(param.userid) && s.folder_id == param.folderID && s.ownerID.Equals(param.ownserID) && s.folder_type == 1);
                    if (folderStar > 0)
                    {
                        focus_num = focus_num - 1;
                        operateContext.bllSession.T_VRFounderApply.Modify(new T_VRFounderApply { focus_num = focus_num }, s => s.id == apply.id, "focus_num");
                    }
                    return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "取消合伙店铺关注成功！", focus_num);
                }
            }
            else
                //啥也不是
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "合伙人或创始人用户编码 对店铺ID既不是创始人、也不是合伙人！", null);
        }
        #endregion

        #region 4.5 ✔保存店铺点赞 + WebApiResultJsonModel SaveStoreStar(InputSaveStoreStar param)
        /// <summary>
        /// 4.5 ✔保存店铺点赞
        /// </summary>
        /// <param name="param">请求参数</param>
        /// <returns></returns>
        [HttpPost]
        [ModelValid]
        public WebApiResultJsonModel SaveStoreStar(InputSaveStoreStar param)
        {
            //1.0、用户编码
            var user_id = SysPermissSession.ChangeIdByGuid(param.userid);
            if (user_id <= 0)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "登录用户编码信息异常！", null);
            var owner_id = SysPermissSession.ChangeIdByGuid(param.ownserID);
            if (owner_id <= 0)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "合伙人或创始人用户编码信息异常 ！", null);
            //1.1、店铺
            var folder = operateContext.bllSession.T_DocumentFolder.FindSingle(s => s.folder_id == param.folderID);
            if (null == folder)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "店铺id异常！", null);
            //2.0、关注店铺【ownerID是创始人】
            if (folder.founder_id == owner_id)
            {
                var star = operateContext.bllSession.T_VRUserFolderStar.SelectCount(s => s.user_guid.Equals(param.userid) && s.folder_id == param.folderID && s.folder_type == 0);
                int star_num = folder.star_num;
                //加点赞
                if (param.status == 1)
                {
                    if (star > 0)
                        return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "已添加过点赞！", star_num);
                    var folderStar = operateContext.bllSession.T_VRUserFolderStar.Add(new T_VRUserFolderStar
                    {
                        user_guid = param.userid,
                        folder_id = folder.folder_id,
                        folder_pid = folder.folder_pid,
                        folder_path = folder.folder_path,
                        folder_type = 0,
                        partner_id = 0,
                        folder_date = DateTime.Now
                    });
                    if (folderStar > 0)
                    {
                        star_num += 1;
                        operateContext.bllSession.T_DocumentFolder.Modify(new T_DocumentFolder { star_num = star_num }, s => s.folder_id == folder.folder_id, "star_num");
                    }
                    return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "添加店铺点赞成功！", star_num);
                }
                //取消点赞
                else
                {
                    if (star <= 0)
                        return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "当前用户并未点赞过该店铺无需取消！", star_num);
                    var folderStar = operateContext.bllSession.T_VRUserFolderStar.Delete(s => s.user_guid.Equals(param.userid) && s.folder_id == param.folderID && s.folder_type == 0);
                    if (folderStar > 0)
                    {
                        star_num -=  1;
                        operateContext.bllSession.T_DocumentFolder.Modify(new T_DocumentFolder { star_num = star_num }, s => s.folder_id == folder.folder_id, "star_num");
                    }
                    return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "取消店铺点赞成功！", star_num);
                }
            }
            //2.1、关注合伙店铺
            var apply = operateContext.bllSession.T_VRFounderApply.FindSingle(s => s.user_id == owner_id && s.folder_id == param.folderID && s.apply_status == 1);
            //店铺合伙人
            if (null != apply)
            {
                //合伙人店铺
                var star = operateContext.bllSession.T_VRUserFolderStar.SelectCount(s => s.user_guid.Equals(param.userid) && s.folder_id == param.folderID && s.ownerID.Equals(param.ownserID) && s.folder_type == 1);
                int star_num = apply.star_num;
                //加点赞
                if (param.status == 1)
                {
                    if (star > 0)
                        return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "已添加过点赞！", star_num);
                    var folderStar = operateContext.bllSession.T_VRUserFolderStar.Add(new T_VRUserFolderStar
                    {
                        user_guid = param.userid,
                        folder_id = folder.folder_id,
                        folder_pid = folder.folder_pid,
                        folder_path = folder.folder_path,
                        folder_type = 1,
                        ownerID = param.ownserID,
                        partner_id = apply.id,
                        folder_date = DateTime.Now
                    });
                    if (folderStar > 0)
                    {
                        star_num += 1;
                        operateContext.bllSession.T_VRFounderApply.Modify(new T_VRFounderApply { star_num = star_num }, s => s.id == apply.id, "star_num");
                    }
                    return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "添加店铺点赞成功！", star_num);
                }
                //取消点赞
                else
                {
                    if (star <= 0)
                        return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "当前用户并未点赞过该合伙店铺无需取消！", star_num);
                    var folderStar = operateContext.bllSession.T_VRUserFolderStar.Delete(s => s.user_guid.Equals(param.userid) && s.folder_id == param.folderID && s.ownerID.Equals(param.ownserID) && s.folder_type == 1);
                    if (folderStar > 0)
                    {
                        star_num -=  1;
                        operateContext.bllSession.T_VRFounderApply.Modify(new T_VRFounderApply { star_num = star_num }, s => s.id == apply.id, "star_num");
                    }
                    return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "取消合伙店铺点赞成功！", star_num);
                }
            }
            else
                //啥也不是
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "合伙人或创始人用户编码 对店铺ID既不是创始人、也不是合伙人！", null);
        }
        #endregion

        #region 4.6 ✔ 获取店铺详情 + WebApiResultJsonModel<OutputGetStoreDetail> GetStoreDetail(InputGetStoreDetail param)
        /// <summary>
        /// 4.6 ✔ 获取店铺详情
        /// </summary>
        /// <param name="param">请求参数</param>
        /// <returns></returns>
        [HttpPost]
        [ModelValid]
        public WebApiResultJsonModel<OutputGetStoreDetail> GetStoreDetail(InputGetStoreDetail param)
        {
            //1.0、用户编码
            var user_id = SysPermissSession.ChangeIdByGuid(param.userid);
            if (user_id <= 0)
                return ApiResultJsonModel<OutputGetStoreDetail>.RedirectWebApi(WebResultCode.Exception, "登录用户编码信息异常！", null);
            var owner_id = SysPermissSession.ChangeIdByGuid(param.ownserID);
            //1.1、店铺id
            var folder = operateContext.bllSession.T_DocumentFolder.FindSingle(s => s.folder_id == param.folderID);
            if (null == folder)
                return ApiResultJsonModel<OutputGetStoreDetail>.RedirectWebApi(WebResultCode.Exception, "店铺id异常！", null);
            var apply = operateContext.bllSession.T_VRFounderApply.SelectCount(s => s.user_id == owner_id && s.folder_id == param.folderID && s.apply_status == 1);
            //1.2、既不是创始人、也不是合伙人
            if (owner_id > 0 && folder.founder_id != owner_id && apply <= 0)
                return ApiResultJsonModel<OutputGetStoreDetail>.RedirectWebApi(WebResultCode.Exception, "获取数据失败，没有该合伙人的店铺！", null);
            string storeType = string.Empty;
            // 2.0、owner_id创始人或为空
            if (string.IsNullOrEmpty(param.ownserID) || owner_id == folder.founder_id)
                storeType = "owner";
            //2.1、店铺合伙人 apply > 0
            var OutputGetStoreDetail = operateContext.bllSession.T_VRAreaInfo.GetStoreDetail(param, storeType, owner_id, user_id);
            //2.2、店铺协议地址
            var dealID = operateContext.bllSession.T_VRFounderDeal.FindSingle(s => s.folder_id == param.folderID)?.id;
            if(null!= dealID)
                OutputGetStoreDetail.dealUrl= HttpContext.Current.Request.Url.AbsoluteUri.Substring(0, HttpContext.Current.Request.Url.AbsoluteUri.IndexOf("/api/")) + $"/uploadFile/FouderPact/FouderPact.html?id={dealID}";
            //2.3、根协议地址
            int rootId = operateContext.bllSession.T_VRUserLevel.GetRootIdByStore(param.folderID);
            var rootdealID = operateContext.bllSession.T_VRFounderDeal.FindSingle(s => s.folder_id == rootId)?.id;
            if(null!= rootdealID)
                OutputGetStoreDetail.dealUrlRoot = HttpContext.Current.Request.Url.AbsoluteUri.Substring(0, HttpContext.Current.Request.Url.AbsoluteUri.IndexOf("/api/")) + $"/uploadFile/FouderPact/FouderPact.html?id={rootdealID}";
            return ApiResultJsonModel<OutputGetStoreDetail>.RedirectWebApi(WebResultCode.Ok, "获取成功", OutputGetStoreDetail);
        }
        #endregion
    }
}